package com.zzy.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class AdminController {


    @RequestMapping(value = "/login2")
    public String login2(@RequestParam(value = "error", required = false) String error, Model model, HttpServletRequest request) {
        if (error != null) {//登录失败
            request.setAttribute("error",error);
            return "login";
        }
        return "login";//首次进入的页面
    }
    //登录成功的页面
    @RequestMapping(value = "/welcome")
    public ModelAndView welcomes() {
        ModelAndView welcome = new ModelAndView();
        welcome.addObject("title","welcome");
        welcome.addObject("message","this is a security page");
        welcome.setViewName("hello");
        return welcome;
    }


    // 登录成功 默认 的跳转页面
    @RequestMapping(value= {"/","/welcome**"},method=RequestMethod.GET)
    public ModelAndView welcome() {
        ModelAndView welcome = new ModelAndView();
        welcome.addObject("title","welcome");
        welcome.addObject("message","this is a security page");
        welcome.setViewName("hello");
        return welcome;
    }

    @RequestMapping(value="/admin**",method=RequestMethod.GET)
    public ModelAndView admin() {
        ModelAndView welcome = new ModelAndView();
        welcome.addObject("title","admin");
        welcome.addObject("message","this is a admin page");
        welcome.setViewName("admin");
        return welcome;
    }

    @RequestMapping(value="/logout**",method=RequestMethod.GET)
    public ModelAndView logout() {
        ModelAndView welcome = new ModelAndView();

        welcome.setViewName("index");
        return welcome;
    }

}
